package com.gmail.bogatyr.alexander.client.presenter;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Label;
import net.customware.gwt.presenter.client.EventBus;
import net.customware.gwt.presenter.client.widget.WidgetDisplay;
import net.customware.gwt.presenter.client.widget.WidgetPresenter;

public class TelephoneBookDisplayPresenter extends WidgetPresenter<TelephoneBookDisplayPresenter.Display> {

    public TelephoneBookDisplayPresenter(Display display, EventBus eventBus) {
        super(display, eventBus);
    }

    public interface Display extends WidgetDisplay {
        public Label getTitleLabel();
        public Label getNumberLabel();
        public Label getNameLabel();
        public HasClickHandlers getEditButton();
        public HasClickHandlers getDeleteButton();
        public HasClickHandlers getBackButton();
    }
    
    @Override
    protected void onBind() {
        display.getTitleLabel().setText("Telephone Book View Contact ...");
        registerHandler(display.getEditButton().addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                Window.alert("Redirect to Edit");
            }
        }));
        registerHandler(display.getDeleteButton().addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                Window.alert("Delete contact " + display.getNumberLabel().getText() + " " +
                        display.getNameLabel().getText());
            }
        }));
        registerHandler(display.getBackButton().addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                Window.alert("Redirect to Contacts List");
            }
        }));
    }

    @Override
    protected void onUnbind() {
        //nothing
    }

    @Override
    protected void onRevealDisplay() {
        //nothing
    }
}
